home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d26 / cattest.arc / INITQUES.IN1 < prev    next >
Text File  |  1991-07-01  |  5KB  |  160 lines

  1. PROCEDURE Init_Question;
  2.  
  3. VAR 
  4.   {problem oriented variables follow}
  5. {integer variables}
  6.     I_num_1,I_num_2 : Integer;
  7.  
  8. {real variables}
  9.     R_1, { price of first item}
  10.     R_2, { price of second item }
  11.     R_3: REAL;  { total amount of money available }
  12.     final_item_one,
  13.     final_item_two,
  14.     final_total_dollars,
  15.     final_total_amount : REAL;
  16.  
  17. {string variables}
  18.     A_R_1,A_R_2,A_R_3: STRING; { STRING equivalents of above for printing }
  19.     A_final_item_one,
  20.     A_final_item_two,
  21.     A_final_total_dollars,
  22.     A_final_total_amount : STRING;
  23.  
  24. CONST
  25.   A_1 : ARRAY [1..3] OF STRING = ('Peanuts','Almonds','Walnuts');
  26.   A_2 : ARRAY [1..3] OF STRING = ('Cashews','Macadamia','Brazil nuts');
  27.  
  28. BEGIN
  29. {$I-}
  30.   Assign(OldQuestionFile,Progname_String+'.SAV');
  31.   Reset(OldQuestionFile);
  32. {$I+}
  33.   IF IOResult = 0
  34.     THEN {there was a save file}
  35.       BEGIN
  36.         ReadLn(OldQuestionFile,
  37.                I_num_1);
  38.         ReadLn(OldQuestionFile,I_num_2);
  39.         ReadLn(OldQuestionFile,R_1);
  40.         ReadLn(OldQuestionFile,R_2);
  41.         ReadLn(OldQuestionFile,final_item_one);
  42.         ReadLn(OldQuestionFile,final_item_two);
  43.         Close(OldQuestionFile);
  44.       END
  45.     ELSE   {there was no save file, create one}
  46.       BEGIN
  47. { question creation section
  48. in this section we create the variables which will change between
  49. students.}
  50.  
  51.         I_num_1 := random(3)+1;
  52.         I_num_2 := random(3)+1;
  53.         R_1 := 10*(Random); { price of first item }
  54.         R_2 := 10.*Random + R_1; { price of second item }
  55.  
  56.         final_item_one := 3.* Random;
  57.         final_item_two := 3.* Random;
  58.  
  59.  
  60.         ReWrite(OldQuestionFile); {create the .SAV file if none existed,
  61.                      so if student returns to this
  62.                      question, the same variables will
  63.                      appear }
  64.         Writeln(OldQuestionFile,
  65.                 I_num_1);
  66.         Writeln(OldQuestionFile,I_num_2);
  67.         Writeln(OldQuestionFile,R_1);
  68.         Writeln(OldQuestionFile,R_2);
  69.         Writeln(OldQuestionFile,final_item_one);
  70.         Writeln(OldQuestionFile,final_item_two);
  71.         Close(OldQuestionFile);
  72.       END;
  73.  
  74. {the following variables are dependent on the student's variables}
  75.   Str(R_1:3:2,A_R_1);
  76.   Str(R_2:3:2,A_R_2);
  77.   final_total_dollars := final_item_one*R_1 + final_item_two*R_2;
  78.   final_total_amount := final_item_one + final_item_two;
  79.   Str(final_item_one:5:2,A_final_item_one);
  80.   Str(final_item_two:5:2,A_final_item_two);
  81.   Str(final_total_dollars:5:2,A_final_total_dollars);
  82.   Str(final_total_amount:5:2,A_final_total_amount);
  83.   true_answer := final_item_two;
  84.  
  85.   question :=   A_1[I_num_1]+' cost $'+A_R_1+' per pound.';
  86.   question := question + ' '+A_2[I_num_2]+' cost $'+A_R_2+' per pound.';
  87.   question := question + ' If a person wished to purchase '+
  88.               A_final_total_amount+ ' pounds of nuts and wishes ';
  89.   question := question  + ' to spend $'+A_final_total_dollars+' for nuts, how many ' ;
  90.   question := question  + 'pounds of '+A_2[I_num_2]+' should that person purchase?' ;
  91.   IF MaxAvail < Sizeof(Wrong_Answers) {repeat this for each error response}
  92.     THEN
  93.       BEGIN
  94.         ClrScr;
  95.         WriteLn('Not Enough Memory For Errors');
  96.         Noise(Bad);
  97.       END
  98.     ELSE
  99.       New(RootErrorPtr);
  100.   TempPtr := RootErrorPtr;
  101.   TempPtr^.value := final_total_amount;
  102.   TempPtr^.remark := 'Did you calculate the total amount of nuts?';
  103.   IF MaxAvail < Sizeof(Wrong_Answers)
  104.     THEN
  105.       BEGIN
  106.         ClrScr;
  107.         WriteLn('Not Enough Memory For Errors');
  108.         Noise(Bad);
  109.       END
  110.     ELSE
  111.       New(GenTempPtr);
  112.   TempPtr^.Next := GenTempPtr;
  113.   TempPtr := GenTempPtr;
  114.   TempPtr^.value := (final_total_dollars - R_2*final_total_amount)/(R_1-R_2);
  115.   TempPtr^.remark := 'Did you mix up '+A_1[I_num_1]+ ' and '+A_2[I_num_2]+'?';
  116.   TempPtr^.Next := NIL;
  117.  
  118. {$IFDEF Watch_Student}
  119.   WriteLn(OutFile,Time_Stamp);
  120.   WriteLn(OutFile,question);
  121.   WriteLn(OutFile,'final_item_one[',A_1[I_num_1]+'] = ',final_item_one);
  122.   WriteLn(OutFile,'final_item_two['+A_2[I_num_2]+'] = ',final_item_two);
  123.   WriteLn(OutFile,'final_total_dollars = ', final_total_dollars);
  124.   WriteLn(OutFile,'final_total_amount = ',final_total_amount);
  125. {$ENDIF}
  126.   IF MaxAvail < Sizeof(Debug_Lines) {repeat this for each debug response}
  127.     THEN
  128.       BEGIN
  129.         ClrScr;
  130.         WriteLn('Not Enough Memory For Errors');
  131.         Noise(Bad);
  132.       END
  133.     ELSE
  134.       BEGIN
  135.         New(TempDebugLinePtr);
  136.         RootDebugLinePtr := TempDebugLinePtr;
  137.         TempDebugLinePtr^.line := 'final_item_one['+A_1[I_num_1]+'] = '+A_final_item_one;
  138.         TempDebugLinePtr^.next := NIL;
  139.       END;
  140.     IF MaxAvail < Sizeof(Debug_Lines)
  141.       THEN
  142.         BEGIN
  143.           ClrScr;
  144.           WriteLn('Not Enough Memory For Errors');
  145.           Noise(Bad);
  146.         END
  147.       ELSE BEGIN
  148.              New(GenTempDebugPtr);
  149.  
  150.              TempDebugLinePtr^.next := GenTempDebugPtr;
  151.              TempDebugLinePtr := GenTempDebugPtr;
  152.              TempDebugLinePtr^.line := 'final_item_two['+A_2[I_num_2]+'] = '+
  153.                                        A_final_item_two;
  154.              TempDebugLinePtr^.next := NIL;
  155.         END;
  156.   Choice_Line :=
  157.                  'How many pounds of '+A_2[I_num_2]+' should this person buy?';
  158.  
  159. END;
  160.